Skip to content

Sourcery refactored main branch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Mar 2, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from namurphy March 2, 2022 16:11
if isinstance(data, list):
self._str = data
else:
self._str = data.split('\n') # store string as list of lines

self._str = data if isinstance(data, list) else data.split('\n')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Reader.__init__ refactored with the following changes:

This removes the following comments ( why? ):

# store string as list of lines

if not self.eof():
out = self[self._l]
self._l += 1
return out
else:
if self.eof():
return ''
out = self[self._l]
self._l += 1
return out
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Reader.read refactored with the following changes:

Comment on lines -91 to +86
if self._l + n < len(self._str):
return self[self._l + n]
else:
return ''
return self[self._l + n] if self._l + n < len(self._str) else ''
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Reader.peek refactored with the following changes:

Comment on lines -231 to +223
if single_element_is_type:
arg_name, arg_type = '', header
else:
arg_name, arg_type = header, ''

arg_name, arg_type = ('', header) if single_element_is_type else (header, '')
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NumpyDocString._parse_param_list refactored with the following changes:

Comment on lines -381 to +369
section_names = set([section for section, content in sections])
section_names = {section for section, content in sections}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function NumpyDocString._parse refactored with the following changes:

Comment on lines -340 to +333
for line in self['References']:
m = re.match(r'.. \[([a-z0-9._-]+)\]', line, re.I)
if m:
items.append(m.group(1))
items.extend(
m.group(1)
for line in self['References']
if (m := re.match(r'.. \[([a-z0-9._-]+)\]', line, re.I))
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SphinxDocString._str_references refactored with the following changes:

Comment on lines -350 to +351
if (self.use_plots and re.search(IMPORT_MATPLOTLIB_RE, examples_str)
and 'plot::' not in examples_str):
out = []
out += self._str_header('Examples')
out += ['.. plot::', '']
out += self._str_indent(self['Examples'])
out += ['']
return out
else:
if (
not self.use_plots
or not re.search(IMPORT_MATPLOTLIB_RE, examples_str)
or 'plot::' in examples_str
):
return self._str_section('Examples')
out = []
out += self._str_header('Examples')
out += ['.. plot::', '']
out += self._str_indent(self['Examples'])
out += ['']
return out
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SphinxDocString._str_examples refactored with the following changes:

Comment on lines -385 to +377
ns = dict((k, '\n'.join(v)) for k, v in ns.items())
ns = {k: '\n'.join(v) for k, v in ns.items()}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SphinxDocString.__str__ refactored with the following changes:

Comment on lines -51 to +63
m = re.match(r'^\.\. +\[(%s)\]' %
app.config.numpydoc_citation_re,
line, re.I)
if m:
if m := re.match(
r'^\.\. +\[(%s)\]' % app.config.numpydoc_citation_re, line, re.I
):
references.add(m.group(1))

if references:
# we use a hash to mangle the reference name to avoid invalid names
sha = hashlib.sha256()
sha.update(name.encode('utf8'))
prefix = 'R' + sha.hexdigest()[:HASH_LEN]
prefix = f'R{sha.hexdigest()[:HASH_LEN]}'

for r in references:
new_r = prefix + '-' + r
new_r = f'{prefix}-{r}'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function rename_references refactored with the following changes:

Comment on lines -230 to +232
sig = (doc['Signature']
or _clean_text_signature(getattr(obj, '__text_signature__', None)))
if sig:
if sig := (
doc['Signature']
or _clean_text_signature(getattr(obj, '__text_signature__', None))
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function mangle_signature refactored with the following changes:

Comment on lines -287 to -289
metadata = {'version': __version__,
return {'version': __version__,
'parallel_read_safe': True}
return metadata
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function setup refactored with the following changes:

Comment on lines -312 to +314
# Ensure that the validation check set contains only valid error codes
invalid_error_codes = config.numpydoc_validation_checks - valid_error_codes
if invalid_error_codes:
if (
invalid_error_codes := config.numpydoc_validation_checks
- valid_error_codes
):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function update_config refactored with the following changes:

This removes the following comments ( why? ):

# Ensure that the validation check set contains only valid error codes

Comment on lines -425 to +423
for i, line in enumerate(lines):
for line in lines:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function match_items refactored with the following changes:

for maxsplit in range(0, name.count(".") + 1):
for maxsplit in range(name.count(".") + 1):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Validator._load_obj refactored with the following changes:

and not (not signature_params and not all_params)
and (signature_params or all_params)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Validator.parameter_mismatches refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

Comment on lines -151 to +154
results = []
tokens = pattern.split(s)
n = len(tokens)
if n > 1:
results = []
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function make_xref._split_and_apply_re refactored with the following changes:

for ii, (aa, bb) in enumerate(zip(a, b)):
for aa, bb in zip(a, b):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function line_by_line_compare refactored with the following changes:

Comment on lines -808 to -815
if func == 'func_h':
if (
func == 'func_h'
or func not in ['baz.obj_q', '~baz.obj_r']
and func != 'class_j'
and func in ['func_h1', 'func_h2']
):
assert role == 'meth'
elif func == 'baz.obj_q' or func == '~baz.obj_r':
elif func in ['baz.obj_q', '~baz.obj_r']:
assert role == 'obj'
elif func == 'class_j':
assert role == 'class'
elif func in ['func_h1', 'func_h2']:
assert role == 'meth'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_see_also refactored with the following changes:

Comment on lines -1372 to +1375
if obj is None:
# Only instances have actual _data, not classes
return self
else:
return obj._data.axes[self.axis]
return self if obj is None else obj._data.axes[self.axis]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_nonstandard_property.SpecialProperty.__get__ refactored with the following changes:

This removes the following comments ( why? ):

# Only instances have actual _data, not classes

Comment on lines -1390 to +1389
cfg = dict()
cfg = {}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function test_args_and_kwargs refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Mar 2, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.21%.

Quality metrics Before After Change
Complexity 12.73 🙂 11.94 🙂 -0.79 👍
Method Length 48.04 ⭐ 47.83 ⭐ -0.21 👍
Working memory 7.31 🙂 7.31 🙂 0.00
Quality 67.70% 🙂 67.91% 🙂 0.21% 👍
Other metrics Before After Change
Lines 3793 3759 -34
Changed files Quality Before Quality After Quality Change
numpydoc/docscrape.py 67.61% 🙂 67.37% 🙂 -0.24% 👎
numpydoc/docscrape_sphinx.py 62.31% 🙂 62.48% 🙂 0.17% 👍
numpydoc/numpydoc.py 64.05% 🙂 63.98% 🙂 -0.07% 👎
numpydoc/validate.py 60.40% 🙂 61.52% 🙂 1.12% 👍
numpydoc/xref.py 37.18% 😞 37.18% 😞 0.00%
numpydoc/tests/test_docscrape.py 82.79% ⭐ 83.05% ⭐ 0.26% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
numpydoc/validate.py validate 83 ⛔ 615 ⛔ 10 😞 17.01% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
numpydoc/numpydoc.py mangle_docstrings 34 ⛔ 281 ⛔ 17 ⛔ 18.24% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
numpydoc/xref.py make_xref 40 ⛔ 232 ⛔ 13 😞 23.27% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
numpydoc/docscrape.py NumpyDocString._parse_see_also 30 😞 211 ⛔ 14 😞 27.12% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
numpydoc/docscrape_sphinx.py SphinxDocString._str_member_list 28 😞 226 ⛔ 13 😞 28.57% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants